﻿using DXApplication1.cls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DXApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
        List<Friends> listFri = new List<Friends>();
        public MainWindow()
        {
            InitializeComponent();
        }
        private void WindowMain_Loaded(object sender, RoutedEventArgs e)
        {
            this.Left = SystemParameters.WorkArea.Width - 400;
            this.Top = 80;
            List<Recent> listRe = new List<Recent>();//最近的聊天记录
            for (int i = 0; i < 10; i++)
            {
                Recent re = new Recent();
                re.Avatar = "Images/avatar" + i % 2 + ".png";
                re.LastMsg = "最后一条消息，走，去吃饭了！";
                re.Name = "最近的聊天记录" + i;
                listRe.Add(re);
            }
            lvRecent.ItemsSource = listRe;

            //Thread th = new Thread(AutoSideHideOrShow);
            //th.IsBackground = true;
            //th.Start();

        }
        //void AutoSideHideOrShow()
        //{
        //    Thread.Sleep(200);
        //    int sideThickness = 4;//边缘的厚度，窗体停靠在边缘隐藏后留出来的可见部分的厚度  

        //    //如果窗体最小化或最大化了则什么也不做  
        //    if (this.WindowState == WindowState.Minimized || this.WindowState == WindowState.Maximized)
        //    {
        //        return;
        //    }

        //    //如果鼠标在窗体内  
        //    if (System.Windows.Forms.Cursor.Position.X >= this.Left && System.Windows.Forms.Cursor.Position.X < this.Right && System.Windows.Forms.Cursor.Position.Y >= this.Top && System.Windows.Forms.Cursor.Position.Y < this.Bottom)
        //    {
        //        //如果窗体离屏幕边缘很近，则自动停靠在该边缘  
        //        if (this.Top <= sideThickness)
        //        {
        //            this.Top = 0;
        //        }
        //        if (this.Left <= sideThickness)
        //        {
        //            this.Left = 0;
        //        }
        //        if (this.Left >= System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width - sideThickness)
        //        {
        //            this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width;
        //        }
        //    }
        //    //当鼠标离开窗体以后  
        //    else
        //    {
        //        //隐藏到屏幕左边缘  
        //        if (this.Left == 0)
        //        {
        //            this.Left = sideThickness - this.Width;
        //        }
        //        //隐藏到屏幕右边缘  
        //        else if (this.Left == System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width)
        //        {
        //            this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - sideThickness;
        //        }
        //        //隐藏到屏幕上边缘  
        //        else if (this.Top == 0 && this.Left > 0 && this.Left < System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width)
        //        {
        //            this.Top = sideThickness - this.Height;
        //        }
        //    }  
        //}
        private void WindowMain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void txtSearch_GotFocus(object sender, RoutedEventArgs e)
        {
            txtSearch.Background = Brushes.White;
            txtSearch.Text = "";
            imgSearch.Source = new BitmapImage(new Uri("Images/close_dark.png", UriKind.Relative));
        }

        private void txtSearch_LostFocus(object sender, RoutedEventArgs e)
        {
            txtSearch.Background = null;
            txtSearch.Text = "搜索：联系人、多人聊天、群";
            imgSearch.Source = new BitmapImage(new Uri("Images/Search.png", UriKind.Relative));
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void treeMyFriend_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeView tv = (TreeView)sender;
            if (tv.SelectedItem is Friends)
            {

                WindowChart wc = new WindowChart((Friends)tv.SelectedItem);
                wc.Show();
            }
        }

        private void imgClose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Close();
        }

        private void imgMiniSize_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            this.WindowState = WindowState.Minimized;
        }

        private void imgSearch_MouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            if (txtSearch.IsFocused)
            {
                tabCategory.Focus();
            }

        }

        private void lvRecent_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            object obj = ((ListView)sender).SelectedItem;
            if (obj is Recent)
            {
                Recent re = (Recent)obj;
                MessageBox.Show(string.Format("名称是：{0}\n最后一条消息是：{1}", re.Name, re.LastMsg));
            }
        }





        private void imgMail_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            System.Diagnostics.Process.Start("https://mail.qq.com/");
        }

        private void imgPlus_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            System.Diagnostics.Process.Start("https://www.baidu.com/");
        }

        private void imgQzone_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            System.Diagnostics.Process.Start("http://qzone.qq.com/");
        }

    }
}
